package com.ferry.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import com.ferry.domain.Admin;
import com.ferry.mapper.AdminMapper;
import com.ferry.service.AdminService;
import com.ferry.utils.Response;
import com.ferry.utils.ResponseGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class AdminServiceImpl implements AdminService {

    @Autowired
    private AdminMapper adminMapper;

    @Autowired
    private ResponseGenerator generator;

    @Override
    public Response login(String email, String password) {
        QueryWrapper<Admin> wrapper = new QueryWrapper<Admin>().
                eq("ADMIN_EMAIL",email);
        Admin admin = adminMapper.selectOne(wrapper);
        if (admin != null) {
            if (admin.getAdminPassword().equals(password)) {
                return generator.success("登陆成功",admin);
            } else {
                return generator.fail("密码错误");
            }
        } else {
            return generator.error("管理员不存在");
        }
    }
}
